package com.imopei.beetl.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.imopei.beetl.pojo.User;
import com.imopei.beetl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * discription:
 * author : Weidan
 * Email : toweidan@126.com
 * version : v1.0
 * date : 2016/12/22
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户ID获取ID
     *
     * @return
     */
    @RequestMapping(value = "/getUserById", method = RequestMethod.GET)
    public ModelAndView getUserById() throws JsonProcessingException {
        ModelAndView mv = new ModelAndView("Users");
        User user = new User();
        user.setAge(20);
        user.setPhoneNum("13250033267");
        List<User> users = new ArrayList<>();
        for(int i=0;i<10;i++){
            user.setName("老杨" + i);
            users.add(user);
        }
        for (User user1 : users) {
            System.out.println(user1.getName());
        }
        ObjectMapper objectMapper = new ObjectMapper();

        String s = objectMapper.writeValueAsString(users);


        mv.addObject("user", user);
        mv.addObject("users", users);
        return mv;
    }


}
